// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SwingUtils.java

package com.succez.custom.gssjxt.client;

import java.io.File;
import javax.swing.filechooser.FileFilter;

class _FileFilter extends FileFilter
{

    private String toregex(String s)
    {
        if("*.*".equals(s))
            return ".*";
        StringBuffer sb = new StringBuffer();
        for(int i = 0; i < s.length(); i++)
        {
            char c = s.charAt(i);
            switch(c)
            {
            case 46: // '.'
                sb.append("\\.");
                break;

            case 42: // '*'
                sb.append(".*");
                break;

            case 63: // '?'
                sb.append(".{1}");
                break;

            default:
                if(c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
                {
                    sb.append('[');
                    sb.append(c);
                    sb.append(c < 'a' || c > 'z' ? Character.toLowerCase(c) : Character.toUpperCase(c));
                    sb.append(']');
                } else
                {
                    sb.append(c);
                }
                break;
            }
        }

        return sb.toString();
    }

    public _FileFilter(String filter, String description)
        throws Exception
    {
        String strs1[] = filter.split(";");
        String strs2[] = new String[strs1.length];
        int j = 0;
        for(int i = 0; i < strs1.length; i++)
            if(strs1[i] != null && strs1[i].length() != 0)
                strs2[j++] = toregex(strs1[i]);

        if(j == 0)
        {
            throw new Exception("\u6CA1\u6709\u5408\u6CD5\u7684filter");
        } else
        {
            filters = new String[j];
            System.arraycopy(strs2, 0, filters, 0, j);
            this.description = description;
            return;
        }
    }

    public boolean accept(File f)
    {
        if(f.isDirectory())
            return true;
        String fn = f.getName();
        for(int i = 0; i < filters.length; i++)
            if(fn.matches(filters[i]))
                return true;

        return false;
    }

    public String getDescription()
    {
        return description;
    }

    String filters[];
    String description;
}
